package com.common.frame.utils

import java.io.Closeable
import java.io.IOException

object CloseUtil {

    /**
     * 关闭IO
     *
     * @param closeables closeables
     */
    fun closeIO(vararg closeables: Closeable?) {
        closeables
            .forEach {
                try {
                    it?.close()
                } catch (e: IOException) {
                    e.printStackTrace()
                }
            }
    }

    /**
     * 安静关闭IO
     *
     * @param closeables closeables
     */
    fun closeIOQuietly(vararg closeables: Closeable?) {
        closeables
            .filterNotNull()
            .forEach {
                try {
                    it.close()
                } catch (ignored: IOException) {
                }
            }
    }
}
